package com.goods.business.controller;

import com.goods.business.service.HealthService;
import com.goods.common.model.business.Health;
import com.goods.common.model.system.User;
import com.goods.common.response.ActiveUser;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.HealthVO;
import com.goods.common.vo.system.PageVO;
import com.goods.system.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author liangliang
 * @Date 2021/11/10 22:01 Administrator
 * @Description
 */
@RestController
@RequestMapping("/business/health")
public class HealthController {
    @Autowired
    private HealthService healthService;
    @Autowired
    private UserService userService;
    @GetMapping("/isReport")
    private ResponseBean isReports() {
        ActiveUser activeUser = (ActiveUser) SecurityUtils.getSubject().getPrincipal();
        Long id = activeUser.getUser().getId();
        Health health=healthService.isReport(id);
        return ResponseBean.success(health);
    }
    /**
     * 签到记录
     * @param map
     * @return
     */
    @GetMapping("/history")
    public ResponseBean history(@RequestParam Map map){
        PageVO<HealthVO> healthVOPageVO=healthService.history(map);
        return ResponseBean.success(healthVOPageVO);
    }

    /**
     * 立即打卡
     * @param healthVO
     * @return
     */
    @PostMapping("/report")
    public ResponseBean report(@RequestBody HealthVO healthVO){
        ActiveUser activeUser = (ActiveUser) SecurityUtils.getSubject().getPrincipal();
        Long id = activeUser.getUser().getId();
        healthVO.setUserId(id);
        healthService.report(healthVO);
        return ResponseBean.success();

    }
}
